using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace XFNRelationsPlugIn
{
	/// <summary>
	/// Summary description for XFNRelationsControl.
	/// </summary>
	public class XFNRelationsControl : UserControl
	{
		private Label labelMessage;
		private TextBox txtLink;
        private CheckBox checkBox1;
        private CheckBox checkBox2;
        private CheckBox checkBox3;
        private CheckBox checkBox4;
        private CheckBox checkBox5;
        private CheckBox checkBox6;
        private CheckBox checkBox7;
        private CheckBox checkBox8;
        private CheckBox checkBox9;
        private CheckBox checkBox10;
        private CheckBox checkBox11;
        private CheckBox checkBox12;
        private CheckBox checkBox13;
        private CheckBox checkBox14;
        private CheckBox checkBox15;
        private CheckBox checkBox16;
        private CheckBox checkBox17;
        private CheckBox checkBox18;
        private GroupBox groupBox1;
        private LinkLabel linkLabel1;
        private TextBox txtText;
        private Label label1;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private Container components = null;

		public event EventHandler MessageChanged;

		public XFNRelationsControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.labelMessage = new System.Windows.Forms.Label();
            this.txtLink = new System.Windows.Forms.TextBox();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.checkBox2 = new System.Windows.Forms.CheckBox();
            this.checkBox3 = new System.Windows.Forms.CheckBox();
            this.checkBox4 = new System.Windows.Forms.CheckBox();
            this.checkBox5 = new System.Windows.Forms.CheckBox();
            this.checkBox6 = new System.Windows.Forms.CheckBox();
            this.checkBox7 = new System.Windows.Forms.CheckBox();
            this.checkBox8 = new System.Windows.Forms.CheckBox();
            this.checkBox9 = new System.Windows.Forms.CheckBox();
            this.checkBox10 = new System.Windows.Forms.CheckBox();
            this.checkBox11 = new System.Windows.Forms.CheckBox();
            this.checkBox12 = new System.Windows.Forms.CheckBox();
            this.checkBox13 = new System.Windows.Forms.CheckBox();
            this.checkBox14 = new System.Windows.Forms.CheckBox();
            this.checkBox15 = new System.Windows.Forms.CheckBox();
            this.checkBox16 = new System.Windows.Forms.CheckBox();
            this.checkBox17 = new System.Windows.Forms.CheckBox();
            this.checkBox18 = new System.Windows.Forms.CheckBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.linkLabel1 = new System.Windows.Forms.LinkLabel();
            this.txtText = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // labelMessage
            // 
            this.labelMessage.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.labelMessage.Location = new System.Drawing.Point(3, 36);
            this.labelMessage.Name = "labelMessage";
            this.labelMessage.Size = new System.Drawing.Size(27, 13);
            this.labelMessage.TabIndex = 0;
            this.labelMessage.Text = "Link:";
            // 
            // txtLink
            // 
            this.txtLink.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtLink.Location = new System.Drawing.Point(3, 52);
            this.txtLink.Name = "txtLink";
            this.txtLink.Size = new System.Drawing.Size(191, 20);
            this.txtLink.TabIndex = 1;
            this.txtLink.Text = "http://";
            this.txtLink.TextChanged += new System.EventHandler(this.textBoxMessage_TextChanged);
            // 
            // checkBox1
            // 
            this.checkBox1.AccessibleName = "check";
            this.checkBox1.AutoSize = true;
            this.checkBox1.Location = new System.Drawing.Point(12, 19);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(52, 17);
            this.checkBox1.TabIndex = 2;
            this.checkBox1.Tag = "check";
            this.checkBox1.Text = "friend";
            this.checkBox1.UseVisualStyleBackColor = true;
            // 
            // checkBox2
            // 
            this.checkBox2.AccessibleName = "check";
            this.checkBox2.AutoSize = true;
            this.checkBox2.Location = new System.Drawing.Point(12, 42);
            this.checkBox2.Name = "checkBox2";
            this.checkBox2.Size = new System.Drawing.Size(91, 17);
            this.checkBox2.TabIndex = 3;
            this.checkBox2.Tag = "check";
            this.checkBox2.Text = "acquaintance";
            this.checkBox2.UseVisualStyleBackColor = true;
            // 
            // checkBox3
            // 
            this.checkBox3.AccessibleName = "check";
            this.checkBox3.AutoSize = true;
            this.checkBox3.Location = new System.Drawing.Point(12, 65);
            this.checkBox3.Name = "checkBox3";
            this.checkBox3.Size = new System.Drawing.Size(62, 17);
            this.checkBox3.TabIndex = 4;
            this.checkBox3.Text = "contact";
            this.checkBox3.UseVisualStyleBackColor = true;
            // 
            // checkBox4
            // 
            this.checkBox4.AccessibleName = "check";
            this.checkBox4.AutoSize = true;
            this.checkBox4.Location = new System.Drawing.Point(12, 88);
            this.checkBox4.Name = "checkBox4";
            this.checkBox4.Size = new System.Drawing.Size(43, 17);
            this.checkBox4.TabIndex = 5;
            this.checkBox4.Text = "met";
            this.checkBox4.UseVisualStyleBackColor = true;
            // 
            // checkBox5
            // 
            this.checkBox5.AccessibleName = "check";
            this.checkBox5.AutoSize = true;
            this.checkBox5.Location = new System.Drawing.Point(12, 111);
            this.checkBox5.Name = "checkBox5";
            this.checkBox5.Size = new System.Drawing.Size(73, 17);
            this.checkBox5.TabIndex = 6;
            this.checkBox5.Text = "co-worker";
            this.checkBox5.UseVisualStyleBackColor = true;
            // 
            // checkBox6
            // 
            this.checkBox6.AccessibleName = "check";
            this.checkBox6.AutoSize = true;
            this.checkBox6.Location = new System.Drawing.Point(12, 134);
            this.checkBox6.Name = "checkBox6";
            this.checkBox6.Size = new System.Drawing.Size(72, 17);
            this.checkBox6.TabIndex = 7;
            this.checkBox6.Text = "colleague";
            this.checkBox6.UseVisualStyleBackColor = true;
            // 
            // checkBox7
            // 
            this.checkBox7.AccessibleName = "check";
            this.checkBox7.AutoSize = true;
            this.checkBox7.Location = new System.Drawing.Point(12, 157);
            this.checkBox7.Name = "checkBox7";
            this.checkBox7.Size = new System.Drawing.Size(78, 17);
            this.checkBox7.TabIndex = 8;
            this.checkBox7.Text = "co-resident";
            this.checkBox7.UseVisualStyleBackColor = true;
            // 
            // checkBox8
            // 
            this.checkBox8.AccessibleName = "check";
            this.checkBox8.AutoSize = true;
            this.checkBox8.Location = new System.Drawing.Point(12, 180);
            this.checkBox8.Name = "checkBox8";
            this.checkBox8.Size = new System.Drawing.Size(67, 17);
            this.checkBox8.TabIndex = 9;
            this.checkBox8.Text = "neighbor";
            this.checkBox8.UseVisualStyleBackColor = true;
            // 
            // checkBox9
            // 
            this.checkBox9.AccessibleName = "check";
            this.checkBox9.AutoSize = true;
            this.checkBox9.Location = new System.Drawing.Point(12, 203);
            this.checkBox9.Name = "checkBox9";
            this.checkBox9.Size = new System.Drawing.Size(48, 17);
            this.checkBox9.TabIndex = 10;
            this.checkBox9.Text = "child";
            this.checkBox9.UseVisualStyleBackColor = true;
            // 
            // checkBox10
            // 
            this.checkBox10.AccessibleName = "check";
            this.checkBox10.AutoSize = true;
            this.checkBox10.Location = new System.Drawing.Point(107, 19);
            this.checkBox10.Name = "checkBox10";
            this.checkBox10.Size = new System.Drawing.Size(56, 17);
            this.checkBox10.TabIndex = 11;
            this.checkBox10.Text = "parent";
            this.checkBox10.UseVisualStyleBackColor = true;
            // 
            // checkBox11
            // 
            this.checkBox11.AccessibleName = "check";
            this.checkBox11.AutoSize = true;
            this.checkBox11.Location = new System.Drawing.Point(107, 42);
            this.checkBox11.Name = "checkBox11";
            this.checkBox11.Size = new System.Drawing.Size(55, 17);
            this.checkBox11.TabIndex = 12;
            this.checkBox11.Text = "sibling";
            this.checkBox11.UseVisualStyleBackColor = true;
            // 
            // checkBox12
            // 
            this.checkBox12.AccessibleName = "check";
            this.checkBox12.AutoSize = true;
            this.checkBox12.Location = new System.Drawing.Point(107, 65);
            this.checkBox12.Name = "checkBox12";
            this.checkBox12.Size = new System.Drawing.Size(60, 17);
            this.checkBox12.TabIndex = 13;
            this.checkBox12.Text = "spouse";
            this.checkBox12.UseVisualStyleBackColor = true;
            // 
            // checkBox13
            // 
            this.checkBox13.AccessibleName = "check";
            this.checkBox13.AutoSize = true;
            this.checkBox13.Location = new System.Drawing.Point(107, 88);
            this.checkBox13.Name = "checkBox13";
            this.checkBox13.Size = new System.Drawing.Size(40, 17);
            this.checkBox13.TabIndex = 14;
            this.checkBox13.Text = "kin";
            this.checkBox13.UseVisualStyleBackColor = true;
            // 
            // checkBox14
            // 
            this.checkBox14.AccessibleName = "check";
            this.checkBox14.AutoSize = true;
            this.checkBox14.Location = new System.Drawing.Point(107, 111);
            this.checkBox14.Name = "checkBox14";
            this.checkBox14.Size = new System.Drawing.Size(51, 17);
            this.checkBox14.TabIndex = 15;
            this.checkBox14.Text = "muse";
            this.checkBox14.UseVisualStyleBackColor = true;
            // 
            // checkBox15
            // 
            this.checkBox15.AccessibleName = "check";
            this.checkBox15.AutoSize = true;
            this.checkBox15.Location = new System.Drawing.Point(107, 134);
            this.checkBox15.Name = "checkBox15";
            this.checkBox15.Size = new System.Drawing.Size(52, 17);
            this.checkBox15.TabIndex = 16;
            this.checkBox15.Text = "crush";
            this.checkBox15.UseVisualStyleBackColor = true;
            // 
            // checkBox16
            // 
            this.checkBox16.AccessibleName = "check";
            this.checkBox16.AutoSize = true;
            this.checkBox16.Location = new System.Drawing.Point(107, 157);
            this.checkBox16.Name = "checkBox16";
            this.checkBox16.Size = new System.Drawing.Size(47, 17);
            this.checkBox16.TabIndex = 17;
            this.checkBox16.Text = "date";
            this.checkBox16.UseVisualStyleBackColor = true;
            // 
            // checkBox17
            // 
            this.checkBox17.AccessibleName = "check";
            this.checkBox17.AutoSize = true;
            this.checkBox17.Location = new System.Drawing.Point(107, 180);
            this.checkBox17.Name = "checkBox17";
            this.checkBox17.Size = new System.Drawing.Size(78, 17);
            this.checkBox17.TabIndex = 18;
            this.checkBox17.Text = "sweetheart";
            this.checkBox17.UseVisualStyleBackColor = true;
            // 
            // checkBox18
            // 
            this.checkBox18.AccessibleName = "check";
            this.checkBox18.AutoSize = true;
            this.checkBox18.Location = new System.Drawing.Point(107, 203);
            this.checkBox18.Name = "checkBox18";
            this.checkBox18.Size = new System.Drawing.Size(40, 17);
            this.checkBox18.TabIndex = 19;
            this.checkBox18.Text = "me";
            this.checkBox18.UseVisualStyleBackColor = true;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.checkBox17);
            this.groupBox1.Controls.Add(this.checkBox18);
            this.groupBox1.Controls.Add(this.checkBox16);
            this.groupBox1.Controls.Add(this.checkBox15);
            this.groupBox1.Controls.Add(this.checkBox14);
            this.groupBox1.Controls.Add(this.checkBox13);
            this.groupBox1.Controls.Add(this.checkBox12);
            this.groupBox1.Controls.Add(this.checkBox11);
            this.groupBox1.Controls.Add(this.checkBox10);
            this.groupBox1.Controls.Add(this.checkBox9);
            this.groupBox1.Controls.Add(this.checkBox8);
            this.groupBox1.Controls.Add(this.checkBox7);
            this.groupBox1.Controls.Add(this.checkBox6);
            this.groupBox1.Controls.Add(this.checkBox5);
            this.groupBox1.Controls.Add(this.checkBox4);
            this.groupBox1.Controls.Add(this.checkBox3);
            this.groupBox1.Controls.Add(this.checkBox2);
            this.groupBox1.Controls.Add(this.checkBox1);
            this.groupBox1.Location = new System.Drawing.Point(3, 78);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(191, 238);
            this.groupBox1.TabIndex = 20;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Relationships";
            // 
            // linkLabel1
            // 
            this.linkLabel1.AutoSize = true;
            this.linkLabel1.Location = new System.Drawing.Point(15, 319);
            this.linkLabel1.Name = "linkLabel1";
            this.linkLabel1.Size = new System.Drawing.Size(168, 13);
            this.linkLabel1.TabIndex = 21;
            this.linkLabel1.TabStop = true;
            this.linkLabel1.Text = "http://www.analystdeveloper.com";
            this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
            // 
            // txtText
            // 
            this.txtText.Location = new System.Drawing.Point(3, 16);
            this.txtText.Name = "txtText";
            this.txtText.Size = new System.Drawing.Size(191, 20);
            this.txtText.TabIndex = 22;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(0, -1);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(31, 13);
            this.label1.TabIndex = 23;
            this.label1.Text = "Text:";
            // 
            // XFNRelationsControl
            // 
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtText);
            this.Controls.Add(this.linkLabel1);
            this.Controls.Add(this.txtLink);
            this.Controls.Add(this.labelMessage);
            this.Controls.Add(this.groupBox1);
            this.Name = "XFNRelationsControl";
            this.Size = new System.Drawing.Size(202, 338);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		protected virtual void OnMessageChanged(EventArgs e)
		{
			if(MessageChanged != null)
				MessageChanged(this, e);
		}

		private void textBoxMessage_TextChanged(object sender, EventArgs e)
		{
			OnMessageChanged(e);
		}

		public String Message
		{
            //<a title="Gurkan" href="http://www.analystdeveloper.com/blogs/gurkan" target="_blank" rel="me">Gurkan</a>
    
		    get { return "<a " + " href=\"" + txtLink.Text + "\"" + " target=\"_blank\"" + "rel=\"" + XFNRelations() + "\">" + txtText.Text + "</a>"; }
			set { txtLink.Text = value; }
		}
	    
	    public String XFNRelations()
	    {
            string rel = null;
            //object[] controls = this.Controls.Find("checkBox*", true);

            if (checkBox1.Checked == true)
                rel += checkBox1.Text + ",";
            if (checkBox2.Checked == true)
                rel += checkBox2.Text + ",";
            if (checkBox3.Checked == true)
                rel += checkBox3.Text + ",";
            if (checkBox4.Checked == true)
                rel += checkBox4.Text + ",";
            if (checkBox5.Checked == true)
                rel += checkBox5.Text + ",";
            if (checkBox6.Checked == true)
                rel += checkBox6.Text + ",";
            if (checkBox7.Checked == true)
                rel += checkBox7.Text + ",";
            if (checkBox8.Checked == true)
                rel += checkBox8.Text + ",";
            if (checkBox9.Checked == true)
                rel += checkBox9.Text + ",";
            if (checkBox10.Checked == true)
                rel += checkBox10.Text + ",";
            if (checkBox11.Checked == true)
                rel += checkBox11.Text + ",";
            if (checkBox12.Checked == true)
                rel += checkBox12.Text + ",";
            if (checkBox13.Checked == true)
                rel += checkBox13.Text + ",";
            if (checkBox14.Checked == true)
                rel += checkBox14.Text + ",";
            if (checkBox15.Checked == true)
                rel += checkBox15.Text + ",";
            if (checkBox16.Checked == true)
                rel += checkBox16.Text + ",";
            if (checkBox17.Checked == true)
                rel += checkBox17.Text + ",";
            if (checkBox18.Checked == true)
                rel += checkBox18.Text + ",";

            if (rel.LastIndexOf(",") == rel.Length-1)
                rel = rel.Remove(rel.Length-1, 1);


            return rel;
	    }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited = true;
            System.Diagnostics.Process.Start(linkLabel1.Text);

        }
	}
}
